package com.irdstudio.efp.batch.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.util.TimeUtil;
import com.irdstudio.efp.batch.service.facade.SedAntiMoneyLaunderBlackListService;
import com.irdstudio.efp.cus.service.facade.CusT07BlacklistTempService;
import com.irdstudio.efp.cus.service.facade.GreyBlackListService;
import com.irdstudio.efp.cus.service.vo.CusT07BlacklistTempVO;
import com.irdstudio.efp.cus.service.vo.GreyBlackListVO;

/**
 * 需求编号：<br/>
 * 问题编号：<br/>
 * 功能描述：同步个贷反洗钱黑名单服务实现类<br/>
 * 开发人员：周才顺<br/>
 * 创建日期：2019年5月29日 上午10:47:53
 * 
 * @author zhoucs1
 * @since 1.0
 * @version 1.0
 */
@Service("sedAntiMoneyLaunderBlackListService")
public class SedAntiMoneyLaunderBlackListServiceImpl implements SedAntiMoneyLaunderBlackListService {

	// 日志记录器
	private static Logger logger = LoggerFactory.getLogger(SedAntiMoneyLaunderBlackListServiceImpl.class);

	@Override
	public boolean batchAntiMoneyLaunderBlackList() throws Exception {
		logger.info("将反洗钱黑名单临时表中的数据装入正式表开始");
		//查询临时表中的所有数据
		List<CusT07BlacklistTempVO> cusT07BlacklistTempVOList = cusT07BlacklistTempService.queryAll();
		
		//遍历临时表中的所有数据
		for(CusT07BlacklistTempVO cusT07BlacklistTempVO : cusT07BlacklistTempVOList) {
			//以客户号，对象名称，对象键值去查询反洗钱黑名单中是否有记录，有则更新，无则插入
			GreyBlackListVO greyBlackListVO = new GreyBlackListVO();
			greyBlackListVO.setPartyId(cusT07BlacklistTempVO.getPartyId()); //客户号
			greyBlackListVO.setObjName(cusT07BlacklistTempVO.getObjName()); //对象名称
			greyBlackListVO.setObjkey(cusT07BlacklistTempVO.getObjkey()); //对象键值
			GreyBlackListVO newGreyBlackListVO = greyBlackListService.queryByPk(greyBlackListVO);
			if(null != newGreyBlackListVO) {
				setPublicInfo(cusT07BlacklistTempVO,newGreyBlackListVO);
				greyBlackListService.updateByPk(newGreyBlackListVO);
			} else {
				setPublicInfo(cusT07BlacklistTempVO,greyBlackListVO);
				greyBlackListService.insertGreyBlackList(greyBlackListVO);
			}
		}
		logger.info("将反洗钱黑名单临时表中的数据装入正式表结束");
		logger.info("一共成功处理的数据条数为:" + cusT07BlacklistTempVOList.size());
		return true;
	}

	private void setPublicInfo(CusT07BlacklistTempVO cusT07BlacklistTempVO, GreyBlackListVO greyBlackListVO) {
		greyBlackListVO.setOrgankey(cusT07BlacklistTempVO.getOrgankey()); //客户创建机构
		greyBlackListVO.setIsuse(cusT07BlacklistTempVO.getIsuse()); //是否启用
		greyBlackListVO.setPartyClassCd(cusT07BlacklistTempVO.getPartyClassCd()); //客户类型 C:对公 I:对私
		greyBlackListVO.setListType(cusT07BlacklistTempVO.getListType()); //名单类型
		greyBlackListVO.setReasonCreate(cusT07BlacklistTempVO.getReasonCreate()); //名单建立原因
		greyBlackListVO.setReasonCancel(cusT07BlacklistTempVO.getReasonCancel()); //名单取消原因
		greyBlackListVO.setValidateDt(cusT07BlacklistTempVO.getValidateDt()); //生效日期
		greyBlackListVO.setInvalidateDt(cusT07BlacklistTempVO.getInvalidateDt()); //失效日期
		greyBlackListVO.setIsuseNew(cusT07BlacklistTempVO.getIsuseNew()); //是否启用 修改
		greyBlackListVO.setReasonCreateNew(cusT07BlacklistTempVO.getReasonCreateNew()); //名单建立原因  修改
		greyBlackListVO.setValidateDtNew(cusT07BlacklistTempVO.getValidateDtNew()); //生效日期 修改
		greyBlackListVO.setInvalidateDtNew(cusT07BlacklistTempVO.getInvalidateDtNew()); //失效日期 修改
		greyBlackListVO.setExternalId(cusT07BlacklistTempVO.getExternalId()); //客户编号
		greyBlackListVO.setCategory(cusT07BlacklistTempVO.getCategory()); //客户类型
		greyBlackListVO.setTitle(cusT07BlacklistTempVO.getTitle()); //标题
		greyBlackListVO.setNameType(cusT07BlacklistTempVO.getNameType()); //名称类型
		greyBlackListVO.setAddress(cusT07BlacklistTempVO.getAddress()); //通讯地址
		greyBlackListVO.setCity(cusT07BlacklistTempVO.getCity()); //所在城市
		greyBlackListVO.setCountry(cusT07BlacklistTempVO.getCountry()); //所在国家
		greyBlackListVO.setPrograms(cusT07BlacklistTempVO.getPrograms()); //风险类别
		greyBlackListVO.setBirthDate(cusT07BlacklistTempVO.getBirthDate()); //出生日期
		greyBlackListVO.setLastOccupation(cusT07BlacklistTempVO.getLastOccupation()); //职业
		greyBlackListVO.setResidenceCountry(cusT07BlacklistTempVO.getResidenceCountry()); //居住地
		greyBlackListVO.setBirthCountry(cusT07BlacklistTempVO.getBirthCountry()); //出生地
		greyBlackListVO.setNationality(cusT07BlacklistTempVO.getNationality()); //国籍
		greyBlackListVO.setGender(cusT07BlacklistTempVO.getGender()); //性别
		greyBlackListVO.setRemarks(cusT07BlacklistTempVO.getRemarks()); //备注
		greyBlackListVO.setIscheck(cusT07BlacklistTempVO.getIscheck()); //是否申核（1：申批通过，2：添加待申批，3：修改待申批，4：申批未通过）
		greyBlackListVO.setmListType(cusT07BlacklistTempVO.getMListType()); //黑、灰名单类型
		greyBlackListVO.setCardType(cusT07BlacklistTempVO.getCardType()); //证件类型 01:居民身份证、临时居民身份证或户口簿02：军人身份证件或警察身份证件03：港澳居民往来内地通行证、台湾居民往来内地通行证或者其他有效旅行证件04：护照05：其他51:机构代码证
		greyBlackListVO.setCardNo(cusT07BlacklistTempVO.getCardNo()); //证件号码
		greyBlackListVO.setIsPartyId(cusT07BlacklistTempVO.getIsPartyId()); //是否有客户号
		greyBlackListVO.setType(cusT07BlacklistTempVO.getType()); //名单来源分为1人行公开发布和2行内自主创建
		greyBlackListVO.setCardCaption(cusT07BlacklistTempVO.getCardCaption()); //其他证件类型说明
		greyBlackListVO.setOriginName(cusT07BlacklistTempVO.getOriginName()); //原始名称
		greyBlackListVO.setOriginName2(cusT07BlacklistTempVO.getOriginName2()); //存储unicode的原始名称
		greyBlackListVO.setModifyUser(cusT07BlacklistTempVO.getModifyUser()); //最近更新人
		greyBlackListVO.setModifyDt(cusT07BlacklistTempVO.getModifyDt()); //最近更新时间
		greyBlackListVO.setCreateUser(cusT07BlacklistTempVO.getCreateUser()); //创建者
		greyBlackListVO.setCreateDt(cusT07BlacklistTempVO.getCreateDt()); //创建时间
	}

	// 反洗钱黑名单临时表服务
	@Autowired
	private CusT07BlacklistTempService cusT07BlacklistTempService;
	// 反洗钱黑名单服务
	@Autowired
	private GreyBlackListService greyBlackListService;

}
